package com.ny.demo529;

import java.util.Map;
import java.util.HashMap;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        boolean flag = true;
        TestMap testMap = new TestMap();
        Map<String, Emp> empMap = new HashMap<>();
        Scanner scanner = new Scanner(System.in);

        while (flag) {
            TestMap.menu();
            int n = scanner.nextInt();

            switch (n) {
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;

                case 1:
                    System.out.println("添加员工界面");
                    System.out.println("请输入员工信息");
                    System.out.print("请输入员工编号：");
                    String number = scanner.next();
                    System.out.print("请输入员工姓名：");
                    String name = scanner.next();
                    System.out.print("请输入员工年龄：");
                    int age = scanner.nextInt();

                    Emp emp = new Emp(number, name, age);
                    testMap.addEmp(empMap, emp);
                    System.out.println("添加成功，当前员工列表：" + empMap.values());
                    break;

                case 2:
                    System.out.println("查询所有员工信息");
                    testMap.findAllEmp(empMap);
                    break;

                case 3:
                    System.out.println("根据姓名查询员工信息");
                    System.out.println("请输入员工的姓名");
                    String findName = scanner.next();
                    testMap.findEmpName(empMap, findName);
                    break;

                case 4:
                    System.out.println("根据员工编号删除员工");
                    System.out.println("请输入员工的工号");
                    String delNumber = scanner.next();
                    testMap.deleteEmpNumber(empMap, delNumber);
                    break;

                case 5:
                    System.out.println("根据员工编号查询员工");
                    System.out.println("请输入员工的工号");
                    String queryNumber = scanner.next();
                    Emp foundEmp = testMap.findEmpNumber(empMap, queryNumber);
                    System.out.println(foundEmp != null ? foundEmp : "未找到该员工");
                    break;

                case 6:
                    System.out.println("根据员工编号修改年龄");
                    System.out.println("请输入需要修改的员工工号");
                    String updateNumber = scanner.next();
                    System.out.println("请输入新的年龄：");
                    int newAge = scanner.nextInt();
                    testMap.updateEmpAge(empMap, updateNumber, newAge);
                    break;

                default:
                    System.out.println("无效的选择，请重新输入");
            }
        }
        scanner.close();
    }
}